package utils;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class CaptchaResolver {
    private WebDriver driver;

    public CaptchaResolver() {
        ChromeOptions options = new ChromeOptions();
        // 设置浏览器选项，包括用户代理和代理服务器。
        // options.addArguments("--user-agent=your-user-agent");
        // options.addArguments("--proxy-server=http://your-proxy");
        driver = new ChromeDriver(options);
    }

    public void resolveCaptcha(String proxy, String userAgent, String account, String password) {
        try {
            System.out.println("开始解决验证码");
            System.out.println("开始启动模拟器");

            // 启动模拟器
            driver.get("https://sso.garena.com/ui/login?app_id=10100&redirect_uri=https%3A%2F%2Faccount.garena.com%2F%3Flocale_name%3DSG&locale=en-SG");
            WebElement usernameField = driver.findElement(By.name("username"));
            usernameField.sendKeys(account);
            WebElement passwordField = driver.findElement(By.name("password"));
            passwordField.sendKeys(password);

            // 提交登录
            WebElement loginButton = driver.findElement(By.name("login"));
            loginButton.click();

            // 处理验证码
            // ...

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            driver.quit();
        }
    }

    public static void main(String[] args) {
        CaptchaResolver resolver = new CaptchaResolver();
        resolver.resolveCaptcha(null, null, "your-username", "your-password");
    }
}

